package org.gjy.m8.concurrent;

import org.junit.Test;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntUnaryOperator;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-11-21 15:43:26
 */
public class AtomicTest {

    @Test
    public void test3() throws Exception {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);

        Class<? extends ArrayList> cls = list.getClass();
        Field field = cls.getDeclaredField("elementData");
        field.setAccessible(true);
        Object[] objects = (Object[]) field.get(list);
        System.out.println(objects.length);

    }

    @Test
    public void test2() {
        IntUnaryOperator i = (f) -> f * f;
        int c = i.applyAsInt(10);
        System.out.println(c);
        int c2 = i.compose(a -> a + a).applyAsInt(10);
        System.out.println(c2);
        int c3 = i.andThen(a -> a + a).applyAsInt(10);
        System.out.println(c3);
    }

    @Test
    public void test1() {
        AtomicInteger integer = new AtomicInteger();
    }

}
